unit oEntity;

interface
  uses oIStoreable, XMLIntf, math, oStatistics, oCoordinates, sysUtils,
  oSerializer, Classes;

  type
    fMatrix = array of array of integer;

    TEntity = class abstract(TInterfacedObject, IStoreable)
      protected
        aId: Integer;  // entity id
        aMonitor: TStatistics;  // statistics collector
        aPosition : TCoordinates;   // centre of an entity
        aName : string;     // entity name
        aType: Integer; // entity type
        aLevel : integer;
        aVirtual : boolean;
        function GetId: Integer;
        function GetMonitor: TStatistics;
        procedure SetId(NewVal: Integer);
        procedure SetMonitor(NewVal: TStatistics);
      public
        constructor Create; overload;
        constructor Create(paName : string; paId : integer); overload;
        destructor Destroy; override;
        procedure SaveToXML(var paNode : Ixmlnode); virtual;
        procedure LoadFromXML(paNode : IXMLNode); virtual;
        property Monitor:TStatistics read GetMonitor write SetMonitor;
        property Id:Integer read GetId write SetId;
        property Level : integer read aLevel write aLevel;
        property Position : TCoordinates read aPosition write aPosition;
        property Name : string read aName write aName;
        property TypeLogic: Integer read aType write aType;
   //     property Shape : TPhysicalEntity read aShape write aShape;
        property isVirtual : boolean read aVirtual write aVirtual;
    end;

implementation

uses oPhysicalEntity;
{ TEntity }

constructor TEntity.Create;
begin
  aPosition := TCoordinates.Create(0, 0);
  aName := '';
  aVirtual := false;
  aType := 0;
  aId := 0;
end;

constructor TEntity.Create(paName: string; paId: integer);
begin
  Create;
  aName := paName;
  aId := paId;
end;


destructor TEntity.Destroy;
begin
  inherited;
end;

function TEntity.GetId: Integer;
begin
  Result := aId;
end;

function TEntity.GetMonitor: TStatistics;
begin
  Result := aMonitor;
end;

procedure TEntity.LoadFromXML(paNode: IXMLNode);
begin
    TPhysicalEntity.getPoint('position', aPosition, paNode);
    TSerializer.loadValueFromXML(paNode, 'name', aName);
    TSerializer.loadValueFromXML(paNode, 'id', aId);
    TSerializer.loadValueFromXML(paNode, 'level', aLevel);
    TSerializer.loadValueFromXML(paNode, 'type', aType);
    TSerializer.loadValueFromXML(paNode, 'virtual', aVirtual);
end;

procedure TEntity.SaveToXML(var paNode: Ixmlnode);
var
  n : IXMLNode;
begin
  n := paNode.AddChild('entity');
  TPhysicalEntity.addPoint('position', aPosition, n);
  TSerializer.saveValueToXML(n, 'name', aName);
  TSerializer.saveValueToXML(n, 'id', aId);
  TSerializer.saveValueToXML(n, 'type', aType);
  TSerializer.saveValueToXML(n, 'level', aLevel);
  TSerializer.saveValueToXML(n, 'virtual', aVirtual);
end;

procedure TEntity.SetId(NewVal: Integer);
begin
  aId := NewVal;
end;

procedure TEntity.SetMonitor(NewVal: TStatistics);
begin
  aMonitor := NewVal;
end;

end.
